﻿<UserControl x:Class="MultipleFilesInputView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:aeroThemes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             mc:Ignorable="d"
             d:DesignHeight="400"
             d:DesignWidth="600">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <Grid Grid.Row="0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition />
                <RowDefinition />
            </Grid.RowDefinitions>

            <Label Content="Search in Directory" />

            <TextBox Text="{Binding Path=RootDirectoryPath}"
                     Grid.Row="1"
                     Grid.ColumnSpan="2"
                     Margin="0,0,0,4"
                     VerticalAlignment="Center" />

            <CheckBox Content="Include Sub-Directories"
                      IsChecked="{Binding Path=IncludeSubDirectories}"
                      Grid.Row="2"
                      HorizontalAlignment="Right" />

            <Button Content="Browse"
                    Command="{Binding Commands[Browse]}"
                    Grid.Column="1"
                    Grid.Row="2"
                    HorizontalAlignment="Right"
                    VerticalAlignment="Center"
                    Margin="8,0,0,0"
                    Width="72" />
        </Grid>

        <Grid Grid.Row="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition />
            </Grid.RowDefinitions>


            <Label Content="File Name Filter"
                   VerticalAlignment="Center" />

            <Border Grid.Row="1">
                <ComboBox IsEditable="True"
                          Text="{Binding FileNameFilter}">
                    <ComboBoxItem>
                        (?#  C# Code Files  )(?ix) .* [.] (cs|resx|xsd|wsdl|xaml)$</ComboBoxItem>
                    <ComboBoxItem>
                        (?#  Text Files  )(?ix) .* [.] (txt|xml)$</ComboBoxItem>
                    <ComboBoxItem>
                        (?#  VB Code Files  )(?ix) .* [.] (vb|resx|xsd|wsdl|xaml)$</ComboBoxItem>
                    <ComboBoxItem>
                        (?#  Web Code Files  )(?ix) .* [.] (aspx|ascx|asmx|svc|asax|config|asp|asa|xml|htm|html|css)$</ComboBoxItem>
                </ComboBox>
            </Border>

        </Grid>

        <Grid Grid.Row="2">
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="3*"
                                  MinWidth="24" />
                <ColumnDefinition Width="2*"
                                  MinWidth="0" />
            </Grid.ColumnDefinitions>

            <ListView ItemsSource="{Binding MatchingFiles}"
                      SelectedItem="{Binding Path=SelectedFile}"
                      Margin="0,0,4,0">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Vertical"
                                    ToolTip="{Binding Path=FileInfo.FullName}">
                            <TextBlock Text="{Binding Path=FileInfo.Name}" />
                            <TextBlock Text="{Binding Path=RelativePath, StringFormat='{}...{0}'}"
                                       Foreground="Gray"
                                       Margin="4,0,0,0" />
                            <TextBlock Text="{Binding Path=Matches.Count, StringFormat='{}{0} Match(es)'}"
                                       Foreground="Gray"
                                       Margin="4,0,0,0" />
                        </StackPanel>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>

            <GridSplitter Grid.Column="0"
                          Width="4"
                          HorizontalAlignment="Right">

            </GridSplitter>

            <TextBox Text="{Binding Path=SelectedFile, Mode=OneWay}"
                     IsReadOnly="True"
                     Grid.Column="1"
                     HorizontalScrollBarVisibility="Visible"
                     VerticalScrollBarVisibility="Visible">

            </TextBox>

            <Button Content="View Matches"
                    Command="{Binding Path=Commands[ViewMatches]}"
                    Grid.Row="0"
                    Grid.Column="1"
                    HorizontalAlignment="Right"
                    VerticalAlignment="Bottom"
                    Margin="24">
                <!-- 
                    TODO: Have the button dynamically position itself for systems with different scroll bar widths/heights 
                    (System.Windows.SystemParameters.VerticalScrollBarWidth)
                -->
                <Button.Style>
                    <Style TargetType="Button">
                        <Setter Property="Opacity"
                                Value="0.2" />
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Path=SelectedFile}"
                                         Value="{x:Null}">
                                <Setter Property="Visibility"
                                        Value="Hidden" />
                            </DataTrigger>
                            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=Self}, Path=IsMouseOver}"
                                         Value="True">
                                <Setter Property="Opacity"
                                        Value="0.9" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Button.Style>
            </Button>

            <Button Content="Find Files"
                    Command="{Binding Commands[Execute]}"
                    Grid.Row="1"
                    Grid.ColumnSpan="2"
                    Margin="0,8,0,0"
                    HorizontalAlignment="Right"
                    Width="144" />

        </Grid>

    </Grid>
</UserControl>
